package com.wxd.service.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.wxd.bean.UserInfo;
import com.wxd.dao.AccessDB;
import com.wxd.dao.ConnectionManager;
import com.wxd.service.LoginService;

public class LoginServiceImpl implements LoginService {

	public UserInfo getUserInfo(String userName, String userPwd) {
		String sql = "select 1,* from login where 用户名=? and 密码=?";
		Connection conn =null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			//AccessDB accessDB =new AccessDB();
			conn = ConnectionManager.getInstance().getConnection();
			pstm = conn.prepareStatement(sql);
			pstm.setString(1, userName);
			pstm.setString(2, userPwd);

			rs = pstm.executeQuery();

			if (rs.next()) {
				UserInfo ui = new UserInfo();

				ui.setId(rs.getInt(1));
				ui.setUserName(rs.getString(2));
				ui.setDept(rs.getString(3));
				ui.setPhoneNum(rs.getString(4));
				ui.setLimitType(rs.getString(6));
				return ui;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			AccessDB.close(conn, pstm, rs);
		}
		return null;
	}
}
